package com.dw.example.activity;

import java.util.ArrayList;
import java.util.List;

import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;

import com.dw.example.BaseActivity;
import com.dw.example.R;
import com.dw.library.view.CircleIndicator;
import com.dw.library.view.ImageIndicator;
import com.dw.library.view.RectIndicator;
import com.dw.library.view.TextIndicator;
import com.dw.library.view.ViewPagerIndicatorSet;

public class Activity001 extends BaseActivity {

  
  private List<View> mListViews;
  private ViewPager vp;
  private CircleIndicator ci;
  private RectIndicator ri;
  private ImageIndicator ii;
  private TextIndicator ti;

  @Override
  protected void initView() {
    vp = (ViewPager) findViewById(R.id.vp);
    ci = (CircleIndicator) findViewById(R.id.ci);
    ri = (RectIndicator) findViewById(R.id.ri);
    ii = (ImageIndicator) findViewById(R.id.ii);
    ti = (TextIndicator) findViewById(R.id.ti);
    
    LayoutInflater inflater = LayoutInflater.from(this);
    View view1 = inflater.inflate(R.layout.view1, null);
    View view2 = inflater.inflate(R.layout.view2, null);
    View view3 = inflater.inflate(R.layout.view3, null);
    View view4 = inflater.inflate(R.layout.view4, null);
    View view5 = inflater.inflate(R.layout.view5, null);
    mListViews = new ArrayList<View>();
    mListViews.add(view1);
    mListViews.add(view2);
    mListViews.add(view3);
    mListViews.add(view4);
    mListViews.add(view5);
    
    vp.setAdapter(new MyPagerAdapter());
    
    ViewPagerIndicatorSet set = new ViewPagerIndicatorSet(vp);
    set.addIndicator(ci);
    set.addIndicator(ri);
    set.addIndicator(ii);
    set.addIndicator(ti);
    ti.setTitles(new String[]{"类别", "精品商店", "热门免费内容", "热门免费新品", "上升最快"});
  }

  @Override
  protected void initData() {
  }

  @Override
  protected void registListener() {
  }
  
  private class MyPagerAdapter extends PagerAdapter {

    @Override
    public void destroyItem(View container, int position, Object object) {
      ((ViewPager) container).removeView(mListViews.get(position));
    }

    @Override
    public void finishUpdate(View container) {
    }

    @Override
    public int getCount() {
      return mListViews.size();
    }

    @Override
    public Object instantiateItem(View container, int position) {
      ((ViewPager) container).addView(mListViews.get(position), 0);
      return mListViews.get(position);
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
      return arg0 == (arg1);
    }

    @Override
    public void restoreState(Parcelable state, ClassLoader loader) {

    }

    @Override
    public Parcelable saveState() {
      return null;
    }

    @Override
    public void setPrimaryItem(View container, int position, Object object) {

    }

    @Override
    public void startUpdate(View container) {

    }
  }

}
